<?php

/**
 * Framework_Auth
 *
 * This is a change in the auth model, rather than extending from an Auth class
 * your modules should set a member variable to load an auth object which will take 
 * the instance of the module in it's constructor
 * 
 *
 * @author      Ian Szewczyk <roamzero@gmail.com>
 * @copyright   (c) 2007 Ian Szewczyk. All rights reserved.
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @package Framework
 */
abstract class Framework_Auth
{
    /**
     * factory
     *
     * @access 		public
     * @param 		Framework_Module 		$module
     * @return 		mixed 					Instance of Framework_Auth_Common, PEAR_Error
     * @static
     */
    static public function factory(Framework_Module $module)
    {
        $authLayer = $module->authLayer;
    	
    	$file = 'Framework/Auth/'.$authLayer.'.php';
        if (!include_once($file)) {
            return PEAR::raiseError('Could not load authentication file: '.$authLayer);
        }

        $class = 'Framework_Auth_'.$authLayer;
        if (!class_exists($class)) {
            return PEAR::raiseError('Could not find site class: '.$class); 
        }

        try {
            $instance = new $class($module);
            if (!$instance instanceof Framework_Auth_Common) {
                return PEAR::raiseError('Auth class must extend from Framework_Auth_Common');
            }
        } catch (Framework_Exception $error) {
            return PEAR::raiseError($error->getMessage());
        }

        return $instance;
    }
}


?>
